package bite_11_29;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 扑克牌
 */
public class TestDemo {
    // 从1.......13  52张
    private static final String[] suits = {"♥","♠","♣","♦"};

    public static List<Card> lists = new ArrayList<>();

    public static List<Card> buyCard(){
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = suits[i];
                int rank = j;
                lists.add(new Card(suit,rank));
            }
        }
        return lists;
    }

    public static void swap(List<Card> cards,int i,int j){
        Card temp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,temp);
    }
    public static void shuffle(List<Card> cards){
        // 洗牌 ,交换
        for (int i = cards.size()-1; i > 0; i--) {
            Random random = new Random();
            int rank = (random.nextInt(i));
            swap(cards,i,rank);
        }
    }

    public static void take(List<Card> cards){
        ArrayList<Card> cards1 = new ArrayList<>();
        ArrayList<Card> cards2 = new ArrayList<>();
        ArrayList<Card> cards3 = new ArrayList<>();

        ArrayList<ArrayList<Card>> all = new ArrayList<>();
        all.add(cards1);
        all.add(cards2);
        all.add(cards3);

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                Card card = cards.remove(0);
                all.get(i).add(card);
            }
        }
        System.out.println("第1个人的牌"+cards1);
        System.out.println("第2个人的牌"+cards2);
        System.out.println("第3个人的牌"+cards3);
        System.out.println("剩余的牌"+cards);
    }

    public static void main(String[] args) {

        List<Card> cards = TestDemo.buyCard();
        System.out.println("买牌"+cards);
        shuffle(cards);
        System.out.println("洗牌"+cards);
        take(cards);
    }
}

class Card{
    private int rank;// 数字
    private String suit;// 花色

    @Override
    public String toString() {
        return "[ "+ suit + "：" + rank +" ]";
    }

    public Card(String suit,int rank) {
        this.suit = suit;
        this.rank = rank;
    }
}